package com.tensquare.search.controller;

import com.tensquare.search.pojo.Article;
import com.tensquare.search.service.SearchService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("article")
public class SearchController {
    @Autowired
    private SearchService searchService;
    //1.添加文章
    @PostMapping
    public Result add(@RequestBody Article article){
        searchService.add(article);
        return new Result(true, StatusCode.OK,"添加文章成功");
    }
    //2.关键词查询
    @GetMapping("/search/{keywords}/{page}/{size}")
    public Result search(@PathVariable String keywords,@PathVariable int page,@PathVariable int size){
        return new Result(true, StatusCode.OK,"关键词查询成功",searchService.search(keywords,page,size));
    }
}
